    /*  
    championBuilder - Champions Online character planner.
    Copyright (C) 2009 Moritz Hartmeier
    
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You can find the GNU General Public License in the data folder.
    */


package ch.zarzu.champions.builder.gui;

import java.awt.*;
import java.io.*;

import javax.swing.*;
import javax.swing.text.DefaultCaret;

import ch.zarzu.champions.builder.*;
import ch.zarzu.champions.builder.logic.Listener;
import ch.zarzu.util.*;

public class AboutPane extends JLayeredPane {
    private SystemLink sys_link;
    private JEditorPane text;
    private SpringLayout layout;
    private JButton button;
    
    public AboutPane() {
        layout = new SpringLayout();
        setLayout(layout);
        
        sys_link = SystemLink.getInstance();
        
        draw();
    }
    
    private void draw() {
        button = new JButton("<< back");
        button.setFont(new Font("Comic Sans MS", Font.BOLD, 13));
        button.setForeground(Color.WHITE);
        button.setBorderPainted(false);
        button.setBorder(null);
        button.setFocusable(false);
        button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        button.setContentAreaFilled(false);
        button.setActionCommand("backtomain");
        button.addActionListener(Listener.getInstance());
        
        text = new JEditorPane();
        //set the caret to never update, such that the scrollbar is always on top initially
        DefaultCaret caret = new DefaultCaret();
        caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
        text.setCaret(caret);
        text.setEditable(false);
        text.setOpaque(false);
        text.setFocusable(false);
        text.setContentType("text/html");
        text.addHyperlinkListener(Listener.getInstance());
        
        redraw();
    }
    
    public void redraw() {
        removeAll();

        String content = FileSystemWrapper.readFile(new File(AppPath.get() 
                + "data/about.html")).replace("(version)", 
                        App.VERSION).replaceAll(
                                "background-color: #[0-9a-fA-F]{6};", "");
        if(App.DIST.equals("jar5"))
            content = content.replace("<br/>", "<br>");
        text.setText(content);
        
        add(text);
        add(button);
        layout.putConstraint(SpringLayout.EAST, button, 0, SpringLayout.WEST, text);
        layout.putConstraint(SpringLayout.NORTH, button, 15, SpringLayout.NORTH, this);
        layout.putConstraint(SpringLayout.EAST, text, -50, SpringLayout.EAST, this);
        layout.putConstraint(SpringLayout.WEST, text, 150, SpringLayout.WEST, this);
        layout.putConstraint(SpringLayout.NORTH, text, 50, SpringLayout.NORTH, this);
        layout.putConstraint(SpringLayout.SOUTH, this, 0, SpringLayout.SOUTH, text);
    }
}
